Page({
  data: {
    focus: "",
    info: {
      "CustomerContactId": 0,
      "CustomerId": null,
      "PersonName": "",
      "Position": "",
      "Phone": "",
      "Fax": "",
      "Mb": "",
      "Weichat": "",
      "Email": "",
      "QQ": ""
    }
  },
  onLoad(e) {
    var newinfo=this.data.info
    newinfo.CustomerId = e.id
    this.setData({})
  },
  changeValue(e){
    var aftdata = this.data.info
    if(e.target.dataset.parent){
      aftdata[e.target.dataset.parent][e.target.dataset.key] = e.detail.value
    }else{
      aftdata[e.target.dataset.key] = e.detail.value
    }
    this.setData({info:aftdata})
  },
  closeboard() {
    dd.hideKeyboard();
  },
  openboard(e) {
    var _this = this
    setTimeout(() => {
      _this.setData({focus:e.target.dataset.key})
    }, 100);
  },
  save() {
    if(!this.data.info.PersonName){
      dd.showToast({
        type: 'fail',
        content: '联系人名称不能为空'
      });
      return;
    }else if(!this.data.info.Mb){
      dd.showToast({
        type: 'fail',
        content: '联系电话不能为空'
      });
      return;
    }
    getApp().req({
      url: "/customer/contact/add",
      type: "POST",
      data: this.data.info,
      cb(res){
        dd.navigateBack()
      }
    })
  }
});
